package constant;

/**
 * 概率常量类
 */
public class Probabilities {
    // 普通食物出现概率
    public static double NORMAL_FOOD_PROB = 0.5;
    // 加速食物出现概率
    public static double SPEED_UP_FOOD_PROB = 0.4;
    // 护盾食物出现概率
    public static double SHIELD_FOOD_PROB = 0.3;
    // 穿墙食物出现概率
    public static double THROUGH_WALL_FOOD_PROB = 0.3;

    public static int randomProbability (
            double NORMAL_FOOD_PROB,double SPEED_UP_FOOD_PROB,
            double SHIELD_FOOD_PROB,double THROUGH_WALL_FOOD_PROB) {
        // 生成随机数
        double randomValue = Math.random();
        // 根据随机值判断事件结果
        if (randomValue < NORMAL_FOOD_PROB) {
            System.out.println("产生普通食物");
            System.out.println("随机数为："+randomValue);
            return 1;
        } else {
            // 根据随机值判断事件B的具体结果
            double randomValueB = Math.random();
            if (randomValueB < SPEED_UP_FOOD_PROB) {
                //产生加速食物
                System.out.println("产生加速食物");
                System.out.println("随机数为："+randomValueB);
                return 2;
            } else if (randomValueB < SHIELD_FOOD_PROB + SHIELD_FOOD_PROB) {
                System.out.println("产生护盾食物");
                System.out.println("随机数为："+randomValueB);
                return 3;
            } else {
                System.out.println("产生穿墙食物");
                System.out.println("随机数为："+randomValueB);
                return 4;
            }
        }
    }
}
